package com.gem.sms.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**监听器,监听容器启动*/
//注解配置监听器
@WebListener
public class ApplicationListener implements ServletContextListener {

	//当容器启动并且初始化是将会自动调用该方法
	@Override
	public void contextInitialized(ServletContextEvent sce) {
		//获取容器对象
		ServletContext servletContext = sce.getServletContext();
		//获取系统应用路径
		String base = sce.getServletContext().getContextPath();
		//把应用路径存入容器对象
		servletContext.setAttribute("base", base);
	}

	//当容器关闭时,自动调用该方法
	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		ServletContext servletContext = sce.getServletContext();
		servletContext.removeAttribute("base");
	}
}
